// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import axios from 'axios'
import ElementUI from 'element-ui' //新添加
import Vant from 'vant';
import 'vant/lib/index.css';
import globalVariable from '@/components/global_variable.js'
import Blob from './excel/Blob'
import Export2Excel from './excel/Export2Excel.js'
import warnning from './../static/music/warnning.mp3'
import warnning1 from './../static/music/warnning.wav'
import { createSocket,closeSocket } from '@/lib/websocket'
import store from "./store";

Vue.use(Vuex)

Vue.use(ElementUI)

Vue.use(Vant)
//

Vue.config.productionTip = false

axios.defaults.baseURL = 'http://jj.how2go.cn:18086/api'
//axios.defaults.baseURL = 'http://localhost:18086/api'

Vue.prototype.axios = axios

Vue.prototype.global = globalVariable

// 方法1：注册播放音频事件到Vue实例上
Vue.prototype.playAudio = () => {
  let warnningAudio = document.getElementById('warnning');
  warnningAudio.setAttribute('src',warnning1)
  warnningAudio.play()
}

router.beforeEach(function (to, from, next) {
  console.log(to)
  // 检测路由配置中是否有requiresAuth这个meta属性
  if (to.matched.some(record => record.meta.requiresAuth)) {
    // 判断是否已登录
    if (store.getters.isLoggedIn) {
      next();
      return;
    }
    // 未登录则跳转到登录界面
    next('/login');
  } else {
    next()
  }
});

Vue.prototype.createSocket = createSocket

Vue.prototype.closeSocket = closeSocket

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
